<script src="/javascripts/util.js" type="text/javascript"></script>
<script src="/javascripts/calendar.js" type="text/javascript"></script>
<script type="text/javascript">
function checkDate(){
        /*        
        if(document.getElementById("beginDate").value!='' && document.getElementById("endDate").value!=''){
            if (!dateCheck(document.getElementById("beginDate").value))
                alert("开始时间不合法！输入格式为yyyy-mm-dd。");
            else if(!dateCheck(document.getElementById("endDate").value))
                alert("结束时间不合法！输入格式为yyyy-mm-dd。");   
            else
                frmQuery.submit();
        }
        else if(document.getElementById("beginDate").value=='' && document.getElementById("endDate").value=='')
            frmQuery.submit();
        else
            alert("开始时间与结束时间必须全部输入！");
        */
        frmQuery.submit();
    }
function showPaperWindow(id)
{
    window.open("/sale/show_print_sale_paper/"+id,"_blank","height=450,width=700,top=300,left=400,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
}
</script>
<h1>报表中心 - <span id="secondHeading">客户明细</span></h1>
<form id="input-form" action="/query/agent_list" name= "frmQuery" method="post">
<TABLE border="0" id="INPUT_TABLE">
		<tr><td colspan="3">
			<% if @flash[:notice] -%>
					<div id="notice"><%= @flash[:notice] %></div>
				<% end -%>
			</td>
		</tr>
	<TR>
	    <TD width="20%">客户：</TD>
	    <TD><select name="agent_id">
	    <%@agents.each do |agent|%>
	    <option value="<%=agent.id%>"><%=agent.name%></option>
	    <%end%>
            </select>
            </TD>
	</TR>
	<TR>
            <TD>起始时间：</TD>

                <TD>        
                        <!-- <input id="beginDate" type="text" name="from"> -->
                        <script language=javascript>
                                var beignDate=new dateSelector();
                                beignDate.inputID='beginDate';
                                beignDate.inputName='from';
                                beignDate.display();
                        </script>
                </TD>
	</TR>
	<TR>
		<TD>结束时间：</TD>
                <TD>        
                        <!--<input id="endDate" type="text" name="to">-->
                        <script language=javascript>
                                var endDate=new dateSelector();
                                endDate.inputID='endDate';
                                endDate.inputName='to';
                                endDate.display();
                        </script>
                </TD>
	</TR>
	<TR><TD colspan="2" align="right"><input type="button" class="sub" value="查询" onclick="checkDate()"></TD></TR>
</TABLE>
<%=end_form_tag%>
<%if @agentList%>
</p>
<TABLE border="0" id="LIST_TB">
	<TR id="LIST_TB_TITLE">
		<TD colspan="2">产品</TD>
                <TD>订单号</TD>
  <TD>发货单号</TD>
		<TD>销售数量（kpcs）</TD>
                <TD>销售日期</TD>
		<TD>单价（元）</TD>
		<TD>价格总计（元）</TD>
	</TR>
	<%@agentList.each do |item|%>
	<TR id="LIST_TB_CONTENT1">
                <TD><%=item.serial%></TD>
		<TD><%=item.name%></TD>
	<TD><a href="javascript:showPaperWindow(<%=item.sale_paper_id%>)"><%=item.sale_paper_id%></a></TD>
		<TD><%=item.serialp%></TD>

		<TD><%=item.current_count%></TD>
      <TD><%=item.sale_date_at%></TD>
		<TD><%=item.price%></TD>
		<TD><%=sprintf("%#.2f",item.price*item.current_count)%></TD>
	</TR>
	<%end%>
</TABLE>
<table>
        <tr>
                <td>
                        <input type="button" value="打印当前页" class="sub" onclick="openPrintWindow('LIST_TB')"/>
                        <input type="button" value="导出当前数据" class="sub" onclick="CellAreaExcel('LIST_TB')"/>
                </td>
        </tr>
</table>
<%end%>
